import { ref } from 'vue'
import { adapter, request } from '@/request'
import type { RequestWrapper } from '@/core/interfaces/common'
import { guideClose } from '@/core/api/user'

interface Data {
  id: number[]
  code: number
}
export default function guideCloseFn() {
  const service = adapter<RequestWrapper<any>>(request)
  const loading = ref(false)
  const response = ref<any>()

  const fetch = (data: Partial<Data>) => {
    const { url, method } = guideClose()
    loading.value = true

    return service({
      config: {
        url,
        method,
        data
      },
      callback: (res) => {
        response.value = res.data.data
      },
      error: (err) => {
        console.log(err)
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [response, fetch, loading] as const
}
